package com.ruoyi.web.controller.pack;

import java.util.List;
import java.math.BigDecimal;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pack.domain.PackLocationLog;
import com.ruoyi.pack.service.IPackLocationLogService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 定位日志Controller
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@RestController
@RequestMapping("/pack/location/log")
public class PackLocationLogController extends BaseController
{
    @Autowired
    private IPackLocationLogService packLocationLogService;

    /**
     * 查询定位日志列表
     */
    @PreAuthorize("@ss.hasPermi('pack:location:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(PackLocationLog packLocationLog)
    {
        startPage();
        List<PackLocationLog> list = packLocationLogService.selectPackLocationLogList(packLocationLog);
        return getDataTable(list);
    }

    /**
     * 导出定位日志列表
     */
    @PreAuthorize("@ss.hasPermi('pack:location:log:export')")
    @Log(title = "定位日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PackLocationLog packLocationLog)
    {
        List<PackLocationLog> list = packLocationLogService.selectPackLocationLogList(packLocationLog);
        ExcelUtil<PackLocationLog> util = new ExcelUtil<PackLocationLog>(PackLocationLog.class);
        util.exportExcel(response, list, "定位日志数据");
    }

    /**
     * 获取定位日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('pack:location:log:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return success(packLocationLogService.selectPackLocationLogByLogId(logId));
    }

    /**
     * 新增定位日志
     */
    @PreAuthorize("@ss.hasPermi('pack:location:log:add')")
    @Log(title = "定位日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PackLocationLog packLocationLog)
    {
        return toAjax(packLocationLogService.insertPackLocationLog(packLocationLog));
    }

    /**
     * 修改定位日志
     */
    @PreAuthorize("@ss.hasPermi('pack:location:log:edit')")
    @Log(title = "定位日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PackLocationLog packLocationLog)
    {
        return toAjax(packLocationLogService.updatePackLocationLog(packLocationLog));
    }

    /**
     * 删除定位日志
     */
    @PreAuthorize("@ss.hasPermi('pack:location:log:remove')")
    @Log(title = "定位日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(packLocationLogService.deletePackLocationLogByLogIds(logIds));
    }
    
    /**
     * 高级查询定位日志列表
     */
    @PreAuthorize("@ss.hasPermi('pack:location:log:list')")
    @GetMapping("/search")
    public TableDataInfo search(
        @RequestParam(required = false) String locatorCode,
        @RequestParam(required = false) String containerCode,
        @RequestParam(required = false) String startTime,
        @RequestParam(required = false) String endTime,
        @RequestParam(required = false) Integer minBatteryLevel,
        @RequestParam(required = false) Integer maxBatteryLevel,
        @RequestParam(required = false) BigDecimal minTemperature,
        @RequestParam(required = false) BigDecimal maxTemperature,
        @RequestParam(required = false) Integer shockLevel,
        @RequestParam(required = false) String uploadAddress)
    {
        startPage();
        List<PackLocationLog> list = packLocationLogService.selectPackLocationLogByCondition(
            locatorCode, containerCode, startTime, endTime,
            minBatteryLevel, maxBatteryLevel, minTemperature, maxTemperature,
            shockLevel, uploadAddress);
        return getDataTable(list);
    }
    
    /**
     * 设备上传定位数据
     */
    @PostMapping("/upload")
    public AjaxResult uploadLocationData(@RequestBody PackLocationLog packLocationLog)
    {
        return toAjax(packLocationLogService.uploadLocationData(packLocationLog));
    }
} 